//---------------------------------------------------------------
//核心业务类
//create by zhuchentong @ 20170418
//---------------------------------------------------------------

var d1 = require("deviceone");
var App = d1.sm("do_App");
var log = require('util/log');
var router = require('config/router')
var event = require('config/event')
var Bind = require('core/bind')
var Base = require('core/base')


// 创建核心类
var Template = d1.Class(Base, function(options, id) {
	Base.initialize.call(this, id);
	

})

/**
 * 创建页面控件事件监听
 * 
 * @param eventObj
 * @returns
 */
function createEventListener() {
	var self = this
	var eventObj = this._options.event
	for ( var id in eventObj) {
		var target
		switch (id) {
		case '$page': {
			target = page
		}
			break;
		default: {
			target = this.getUI(id)
		}
		}

		var eventList = eventObj[id]
		for ( var eventName in eventList) {
			var eventHandle = eventList[eventName]
			var handle = function() {
				var _target = target
				var _eventName = eventName
				var _eventHandle = eventHandle
				_target.on(_eventName, function() {
					log.info(_eventName)
					_eventHandle.apply(self, arguments)
				})
			}
			handle.call(this)
		}
	}
}

/**
 * 注册ui组件
 */
function registerUI(params) {
	params = params || {}

	for ( var key in params) {
		var value = params[key]
		try {
			this._ui[key] = this.getUI(value)
		} catch (ex) {

		}
	}
}

module.exports = function(options) {
	var id = this.__address
	return new Template(options, id)
}